/**
 * 导航图片编辑、新增
 *
 */
define(["app", "js/services/MessageBox", "js/services/MuseService", "js/directives/FileUpload"], function (app) {

    var deps = ["$scope", "$state", "$modal", "$stateParams", "MessageBox", "MuseService"];

    function controller($scope, $state, $modal, $stateParams, MessageBox, MuseService) {
        //获取参数
        var id = $stateParams.id || '';

        $scope.sysGuidePic = {
            state: 1
        };
        $scope.typeList = [{name: "司机端", value: 0}, {name: "乘客端", value: 1}];

        //获取数据
        $scope.getDetail = function () {
            MuseService.get(baseServices_restfulUrl + "sysGuidePic/load.json?id=" + id).success(
                function (data, status, headers, config) {
                    if (data.state == 0) {
                        $scope.sysGuidePic = data.data;
                    } else {
                        MessageBox.error('获取数据失败:' + data.message);
                    }
                })
                .error(function () {
                    MessageBox.error('服务器正在开小差zZZ,获取不到数据');
                });
        };
        if (id) {
            $scope.getDetail();
        }

        //保存
        $scope.saveObj = function () {
            MuseService.postObj(baseServices_restfulUrl + "sysGuidePic/save.json", $scope.sysGuidePic).success(
                function (data, status, headers, config) {
                    if (data.state == 0) {
                        $scope.result = data.data;
                        MessageBox.notify('保存成功!');
                        $state.go('sysGuidePicList');
                    } else {
                        MessageBox.error('保存失败：' + data.message);
                    }
                })
                .error(function () {
                    MessageBox.error('保存失败:服务器正在开小差zZZ');
                });
        };

        // 取消，返回
        $scope.close = function () {
            //$state.go("sysGuidePicList");
            history.back();
        };

        //打开图片预览页面
        $scope.showPic = function (id) {
            var picId = id;
            window.open(baseServices_restfulUrl + "static/views/preview/imgPreview.html?id=" + picId);
        };
    }

    controller.$inject = deps;
    app.lazy.controller("SysGuidePicEditController", controller);
});
